use crate::Vec3;

pub struct Cuboid {
    pub v0: Vec3,   // The minimum vertex
    pub v1: Vec3,   // The maximum vertex
}

impl Cuboid {
    pub fn new(v0: Vec3, v1: Vec3) -> Self {
        Self { v0, v1}
    }

    pub fn move_x(&mut self, x: f32) {
        self.v0.0 += x;
        self.v1.0 += x;
    }

    pub fn move_y(&mut self, y: f32) {
        self.v0.1 += y;
        self.v1.1 += y;
    }

    pub fn move_z(&mut self, z: f32) {
        self.v0.2 += z;
        self.v1.2 += z;
    }

    pub fn includes_xyz(&self, x: f32, y: f32, z: f32) -> bool {
        if x < self.v0.0 || x > self.v1.0 {
            return false
        }

        if y < self.v0.1 || y > self.v1.1 {
            return false
        }

        if z < self.v0.1 || z > self.v1.2 {
            return false
        }

        true
    }

    pub fn includes(&self, p: Vec3) -> bool {
        self.includes_xyz(p.0, p.1, p.2)
    }

    pub fn overlaps(&self, other: &Cuboid) -> bool {
        self.includes(other.v0) ||
        self.includes_xyz(other.v0.0, other.v0.1, other.v1.2) ||
        self.includes_xyz(other.v0.0, other.v1.1, other.v0.2) ||
        self.includes_xyz(other.v0.0, other.v1.1, other.v1.2) ||
        self.includes_xyz(other.v1.0, other.v0.1, other.v0.2) ||
        self.includes_xyz(other.v1.0, other.v0.1, other.v1.2) ||
        self.includes_xyz(other.v1.0, other.v1.1, other.v0.2) ||
        self.includes(other.v1)
    }
}